package com.zn.web.controller;

import com.zn.entity.CustomerMessageRecord;
import com.zn.service.AppCustomerService;
import com.zn.vo.Message;
import com.zn.web.dto.AppCustomerDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by admintrator on 2019/1/3.
 */
@RestController
@RequestMapping("/appCustomer")
public class AppCustomerController {
    private static final Logger LOGGER = LoggerFactory.getLogger(AppCustomerController.class);

    @Autowired
    private AppCustomerService appCustomerService;

    /**
     * 客户留言记录查询
     * @param record
     * @return
     */
    @RequestMapping(value = "/findCustomerMessageRecordList",method = RequestMethod.POST)
    public ResponseEntity<Message> findCustomerMessageRecordList(@RequestBody AppCustomerDto record) {
        try {
            LOGGER.info("findCustomerMessageRecordList.............................."+record.toString());
            List<CustomerMessageRecord> CustomerMessageList = appCustomerService.findCustomerMessageRecordAll(record);
            return ResponseEntity.ok(Message.page(CustomerMessageList));
        }catch (Exception ex){
            LOGGER.error("findCustomerMessageRecordList........."+ex.getMessage());
        }
        return ResponseEntity.ok(Message.SYS_ERROR);
    }

    /**
     * 保存客户留言
     * @param record
     * @return
     */
    @RequestMapping(value = "/saveCustomerMessageRecordList",method = RequestMethod.POST)
    public ResponseEntity<Message> saveCustomerMessageRecordList(@RequestBody CustomerMessageRecord record) {
        try {
            LOGGER.info("saveCustomerMessageRecordList.............................."+record.toString());
            int count = appCustomerService.saveCustomerMessageRecord(record);
            if (count > 0) {
                return ResponseEntity.ok(Message.REQ_SUCCESS);
            }else if (count < 0){
                return ResponseEntity.ok(Message.ARGS_ERROR);
            }else {
                return ResponseEntity.ok(Message.SYS_ERROR);
            }
        }catch (Exception ex){
            LOGGER.error("saveCustomerMessageRecordList........."+ex.getMessage());
            return ResponseEntity.ok(Message.SYS_ERROR);
        }
    }
}
